package jml.defaultimple.util;

import java.util.Comparator;

import jml.def.Title;


public class TittleComparatorImple implements Comparator<Title>
{
	private String sortPattern;
	
	public TittleComparatorImple(String sortPattern)
	{
		this.sortPattern=sortPattern;
	}
	
	
	// genre+artist+year
	@Override
	public int compare(Title t1, Title t2)
	{
		int ret=0;
		boolean seguir=true;
		String atts[]=UString.split(sortPattern,"+");
		for(int i=0; i<atts.length && seguir; i++)
		{
			String[] a1 = (String[])t1.getLabels(atts[i]);
			String[] a2 = (String[])t2.getLabels(atts[i]);
			
			String v1=a1!=null&&a1.length>0?a1[0]:"";
			String v2=a2!=null&&a2.length>0?a2[0]:"";			
			
			ret=v1.compareTo(v2);
			
			seguir=(ret==0);
		}
		
		return ret;
	}
}
